const WxParse = require('../../components/wxParse/wxParse.js');
const app = getApp()

Page({
  data: {
    id: null,
    isLoading: false,
    news: {},
    article: ''
  },
  onLoad: async function (options) {
    const self = this
    self.setData({
      id: options.id
    })

    // var article = '<div>我是HTML代码</div>';

    // console.log(article)



    try {
      self.setData({
        isLoading: true
      })
      const res = await app.ajax({
        url: `http://localhost:8888/news/${self.data.id}`,
        method: 'GET',
      })
      self.setData({
        news: res.data
      })
      WxParse.wxParse('news.detail', 'html', self.data.news.detail, self, 5);
    } catch (e) {
      wx.showToast({
        title: '网络错误，请刷新重试',
        icon: 'none'
      })
    } finally {
      self.setData({
        isLoading: false
      })
    }
  }
})
